home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
326-350
/
disk_331
/
csh
/
src
/
set.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
4KB
|
178 lines
/*
* SET.C
*
* (c)1986 Matthew Dillon 9 October 1986
*
* Version 2.07M by Steve Drew 10-Sep-87
*
* Version 4.01A by Carlo Borreo & Cesare Dieni 17-Feb-90
*
*/
extern struct Window *w;
#define MAXLEVELS (3 + MAXSRC)
struct MASTER {
struct MASTER *next;
struct MASTER *last;
char *name;
char *text;
};
static struct MASTER *Mbase[MAXLEVELS];
char *set_var(level, name, str)
register char *name, *str;
{
register struct MASTER *base = Mbase[level];
register struct MASTER *last;
register int len;
for (len = 0; isalphanum(name[len]); ++len);
while (base != NULL) {
if (strlen(base->name) == len && strncmp (name, base->name, len) == 0) {
Free (base->text);
goto gotit;
}
last = base;
base = base->next;
}
if (base == Mbase[level]) {
base = Mbase[level] = (struct MASTER *)malloc (sizeof(struct MASTER));
base->last = NULL;
} else {
base = (struct MASTER *)malloc (sizeof(struct MASTER));
base->last = last;
last->next = base;
}
base->name = malloc (len + 1);
bmov (name, base->name, len);
base->name[len] = 0;
base->next = NULL;
gotit:
base->text = malloc (strlen(str) + 1);
strcpy (base->text, str);
if (*name=='_') sys_vars();
return (base->text);
}
char *get_var (level, name)
register char *name;
{
register struct MASTER *base = Mbase[level];
register unsigned char *scr;
register int len;
for (scr = (unsigned char *)name; *scr && *scr != 0x80 && *scr != ' ' && *scr != ';' && *scr != '|'; ++scr);
len = scr - name;
while (base != NULL) {
if (strlen(base->name) == len && strncmp (name, base->name, len) == 0)
return (base->text);
base = base->next;
}
return (NULL);
}
unset_level(level)
{
register struct MASTER *base = Mbase[level];
while (base) {
Free (base->name);
Free (base->text);
Free (base);
base = base->next;
}
Mbase[level] = NULL;
}
unset_var(level, name)
char *name;
{
register struct MASTER *base = Mbase[level];
register struct MASTER *last = NULL;
register int len;
for (len = 0; isalphanum(name[len]); ++len);
while (base) {
if (strlen(base->name) == len && strncmp (name, base->name, len) == 0) {
if (base != Mbase[level])
last->next = base->next;
else
Mbase[level] = base->next;
if (base->next != NULL)
base->next->last = last;
if (base == Mbase[level])
Mbase[level] = base->next;
Free (base->name);
Free (base->text);
Free (base);
return (1);
}
last = base;
base = base->next;
}
return (-1);
}
do_unset_var(str, level)
char *str;
{
register unsigned int i;
for (i = 1; i < ac; ++i) unset_var (level, av[i]);
sys_vars();
return 0;
}
do_set_var(command, level)
char *command;
{
register struct MASTER *base = Mbase[level];
register char *str;
switch (ac) {
case 1:
while (base && !dobreak()) {
printf ("\2330m%-10s %s\n", base->name, base->text);
base = base->next;
}
break;
case 2:
if (str=get_var(level,av[1])) printf ("%-10s %s\n", av[1], str);
break;
default:
set_var (level, av[1], next_word (next_word (command)));
if (*av[1]=='_') sys_vars();
break;
}
return 0;
}
sys_vars()
{
register char *str, *t;
extern char trueprompt[100];
if (strcmp(w->Title, str=get_var(LEVEL_SET, v_titlebar)))
SetWindowTitles(w, str, -1L);
S_histlen=(str = get_var(LEVEL_SET, v_hist)) ? atoi(str) : 0;
debug =(get_var(LEVEL_SET, v_debug) !=NULL);
Verbose=(get_var(LEVEL_SET, v_verbose)!=NULL);
if (S_histlen < 2) S_histlen=2;
if ( (str=get_var(LEVEL_SET,v_prompt)) ==NULL) str="$ ";
t=trueprompt;
while (*str)
if (*str=='%' && str[1]=='p') {
str+=2;
strcpy(t,get_var(LEVEL_SET, "_cwd"));
t+=strlen(t);
}
else *t++=*str++;
strcpy(t,"\2330m");
}